<?php
//рус
include_once(_APP_PATH. 'modules/admin/controllers/myblog/myblog_admin_http.php');
class myblog_admin_http_web extends myblog_admin_http
{   
    protected function ControllerInit()
    {

    }    
    
    protected function PrimaryActionInit ($basicActionName)
    {
        $this->_module->GetDecorator()->SetMenuActiveElement('articles/my_blog'); 

        $blog = $this->GetBlogFromQueryId();
        if (!$blog)
        {
        	$this->OutNoBlogMessage();
        	return false;
        }
    }    

    /**
		экшен по-умолчанию
	*/
    public function PrAction()
    {
        $this->out_articlesPr();
    }    
    
    public function out_articlesPrAction()
    {
    	$blog = $this->GetBlogFromQueryId();    	    	
		$this->OutArticles($blog);		
    }
    
    public function add_articlePrAction($entry = null)
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->AddArticle($blog, $entry);  	
    }
    
    public function media_add_articlePrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->AddArticle($blog);  	
    }    
    
    public function save_articlePrAction ()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->SaveArticle($blog);
    }     
    
    public function del_articlePrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->DelArticle($blog); 	
    }
    
    public function save_theme_articlesPrAction()
    {
    	$blog = $this->GetBlogFromQueryId();    	
    	$this->SaveThemeArticles($blog);
    }
    
    public function del_theme_articlePrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->DelThemeArticle($blog);   	
    } 

    public function out_commentsPrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->OutComments($blog);   	
    }

    public function del_commentPrAction()
    {
    	$blog = $this->GetBlogFromQueryId();
    	$this->DelComment($blog);   	
    }     
    
    public function edit_blogPrAction($blog = null)
    {
    	if (!$blog) $blog = $this->GetBlogFromQueryId();

    	$this->actionTitle = 'Свойста блога';
    	
        $t = $this->GetTemplator();
        $t->blog = $blog;
        $this->LoadTemplate($t->render('blogs/_edit_myblog.phtml')); 
        
        $this->_module->GetDecorator()->SetMenuActiveElement('articles/my_blog_edit');     	
    }
    
    public function save_blogPrAction()
    {
        $blog = $this->GetBlogFromQueryId();

        $blog->SetTitle(trim($this->Request()->getPost('title')));
        $blog->SetAbout(trim($this->Request()->getPost('about')));
        $blog->SetDescription(trim($this->Request()->getPost('description')));    

		if ($this->GetBlogsMapper()->Save($blog)) 
        {	  
            $this->Libs()->messanger->createMessage('Данные сохранены');
	       	MozgRoute::Get('http')->Redirect(array('module' => 'admin', 
		        									 'ctrl' => 'myblog'));             
        } 
        else
        {
        	if ($this->GetBlogsMapper()->IsError())
        	{
        		$this->Libs()->messanger->createMessage($this->GetBlogsMapper()->GetErrorMessage(), MESSAGE_ERROR);
        	}
        	else
        	{
	            $this->Libs()->messanger->createMessage('Данные не были сохранены', MESSAGE_ERROR);     		
        	}
        	
        	$this->edit_blogPr($blog);
            return;
        }   	
    }    
    
    protected function OutNoBlogMessage()
    {
    	$this->actionTitle = 'Где мой блог?';
    	
        $t = $this->GetTemplator();
        $this->LoadTemplate($t->render('blogs/_noblog.phtml'));     	
    }
}